package com.vipheyue.educationmp4.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.vipheyue.educationmp4.R;
import com.vipheyue.educationmp4.bean.CourseBean;
import com.vipheyue.educationmp4.bean.GradeBean;
import com.vipheyue.fastlib.utils.Log;

import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.listener.FindListener;
import cn.bmob.v3.listener.SaveListener;

public class CreateTableActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_table);
//        createGradeData();
        createCourse();
    }

    private void createCourse() {
        //query 所有的gradle

        BmobQuery<GradeBean> query = new BmobQuery<GradeBean>();
        query.findObjects(this, new FindListener<GradeBean>() {
            @Override
            public void onSuccess(List<GradeBean> list) {
                for (int x = 5; x < 10; x++) {//TODO 这儿要弄两次
                    GradeBean gradeBean = list.get(x);
                    for (int j = 1; j < 11; j++) {
                        for (int i = 1; i < 6; i++) {
                            CourseBean courseBean = new CourseBean();
                            courseBean.setCourseName(gradeBean.getGradeName() + i+" 序号:"+j);
                            courseBean.setGradeBean(gradeBean);
                            switch (i) {
                                case 1:
                                    courseBean.setRound("第一周期");
                                    break;
                                case 2:
                                    courseBean.setRound("第二周期");
                                    break;
                                case 3:
                                    courseBean.setRound("第三周期");
                                    break;
                                case 4:
                                    courseBean.setRound("第四周期");
                                    break;
                                case 5:
                                    courseBean.setRound("第五周期");
                                    break;

                            }
                            courseBean.setIndex(j);
                            courseBean.setType(0);//MP4 类型
                            courseBean.setUri("http://edump4.oss-cn-qingdao.aliyuncs.com/totalFolder/%E4%B8%80%E7%BA%A7/%E7%AC%AC%E4%B8%80%E5%91%A8%E6%9C%9F/01_03_say_hello_to_Android.mp4");
                            courseBean.save(CreateTableActivity.this, new SaveListener() {
                                @Override
                                public void onSuccess() {
                                    Log.e("success");
                                }

                                @Override
                                public void onFailure(int i, String s) {
                                    Log.e("fail"+s);

                                }
                            });
                        }
                    }

                }

            }

            @Override
            public void onError(int i, String s) {

            }
        });

    }


    private void createGradeData() {
        for (int i = 1; i < 11  ; i++) {
            GradeBean gradeBean = new GradeBean();
            gradeBean.setGradeName(i + "级上下");
            gradeBean.setIndex(i);
            gradeBean.setLevel(i);
            gradeBean.save(this, new SaveListener() {
                @Override
                public void onSuccess() {
                    Log.e("success");
                }

                @Override
                public void onFailure(int i, String s) {
                    Log.e("fail");
                }
            });
        }


    }
}
